package com.gc.controller.checkServlet;

import com.gc.entity.Check;
import com.gc.service.CheckService;
import com.gc.service.impl.CheckServiceImpl;
import com.gc.util.result.R;
import com.google.gson.Gson;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Timestamp;

@WebServlet(name = "checkUpdateById", value = "/checkUpdateById" )
public class checkUpdateById extends HttpServlet {
    CheckService checkService = new CheckServiceImpl();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Gson gson = new Gson();
        Check check = new Check(
                Long.valueOf(request.getParameter("id")),
                request.getParameter("checkid"),
                request.getParameter("bookid"),
                request.getParameter("cid"),
                Integer.valueOf(request.getParameter("stage")),
                Timestamp.valueOf(request.getParameter("starttime")),
                Timestamp.valueOf(request.getParameter("endtime"))
        );
        boolean res = checkService.UpdateById(check);
        if(res) {
            if(res) {
                response.getWriter().write(gson.toJson(R.ok()));
            } else {
                response.getWriter().write(gson.toJson(R.error()));
            }
        }
    }
}
